<?php
/**
 * User: aka
 * Time: 2:39
 */

namespace app\read\controller;

use app\validate\other\QueryOther;
use think\facade\Session;
use think\Request;

class Other
{
    private $userId;

    public function __construct()
    {
        $this->userId = Session::get('user_info.id');
    }

    public function __destruct()
    {
        unset($this->userId);
    }

    public function queryOther(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->type(1)
                ->paginate(10)
                ->each(
                    function($item)
                    {
                        $item->uid = \app\tenno\model\Users::userInfo($item->uid)
                            ->find();
                    }
                );
            return view('query_other', ['other_list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryArcane(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->type(4)
                ->paginate(10)
                ->each(
                    function($item)
                    {
                        $item->uid = \app\tenno\model\Users::userInfo($item->uid)
                            ->find();
                    }
                );
            return view('query_arcane', ['other_list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function querySculpt(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->type(5)
                ->paginate(10)
                ->each(
                    function($item)
                    {
                        $item->uid = \app\tenno\model\Users::userInfo($item->uid)
                            ->find();
                    }
                );
            return view('query_sculpt', ['other_list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryKuWa(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->type(6)
                ->paginate(10)
                ->each(
                    function($item)
                    {
                        $item->uid = \app\tenno\model\Users::userInfo($item->uid)
                            ->find();
                    }
                );
            return view('query_ku_wa', ['other_list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryKuBo(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->type(7)
                ->paginate(10)
                ->each(
                    function($item)
                    {
                        $item->uid = \app\tenno\model\Users::userInfo($item->uid)
                            ->find();
                    }
                );
            return view('query_ku_bo', ['other_list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryUserArcane(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->uid($this->userId)
                ->type(4)
                ->paginate(10);
            return view('query_user_arcane', ['list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryUserOther(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->uid($this->userId)
                ->type(1)
                ->paginate(10);
            return view('query_user_other', ['list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryUserSculpt(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->uid($this->userId)
                ->type(5)
                ->paginate(10);
            return view('query_user_sculpt', ['list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryUserKuWa(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->uid($this->userId)
                ->type(6)
                ->paginate(10);
            return view('query_user_ku_wa', ['list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }

    public function queryUserKuBo(Request $request)
    {
        $validate = new QueryOther();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else {
            $queryStuffName = $request->param('query_stuff_name');
            $otherList = \app\tenno\model\Other::deleteState(0)
                ->stuffName($queryStuffName)
                ->uid($this->userId)
                ->type(7)
                ->paginate(10);
            return view('query_user_ku_bo', ['list' => $otherList, 'query_name' => $queryStuffName]);
        }
    }
}